package com.itbour.service.tg.impl;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.dao.tg.PartnerOrderInfoDao;
import com.itbour.dto.tg.PartnerOrderInfDto;
import com.itbour.dto.tg.PartnerSaleDto;
import com.itbour.service.tg.PartnerOrderInfService;

/**
 * 合伙人订单明细
 * 
 * @author LQ
 */
public class PartnerOrderInfServiceImpl implements PartnerOrderInfService {
	private PartnerOrderInfoDao partnerOrderInfoDao;
	private static double earning_radio=0.1;//收益 计算比例是0.1
	
	
	@Override
	public Page getPartnerOrderInfo(Map<String, Object> parm,Integer pageNo,Integer pageSize) {
		Page result = null;
		// 实际起始位置
		int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
		int totalSize = partnerOrderInfoDao.getPartnerOrdetailCnt(parm);
		while(totalSize >0 && totalSize <= skipResults){//当记录总数 小于 起始位置数
			skipResults= skipResults - pageSize;
			pageNo = pageNo -1;
		}
		// 分页检索
		parm.put("pageSize", pageSize);
		parm.put("skipResults", skipResults);
		
		List<PartnerOrderInfDto> list=new ArrayList<PartnerOrderInfDto>();
		list=partnerOrderInfoDao.getPartnerOrderInf(parm);
		result = new JspPage(skipResults, totalSize, pageSize, list);
		return result;
	}

	public int getPartnerSaleRankCnt(Map<String, Object> parm) {
		return partnerOrderInfoDao.getPartnerSaleCnt(parm);
	}
	@Override
	public Page getPartnerSaleRank(Map<String, Object> parm, Integer pageNo,
			Integer pageSize) {
		Page result = null;
		try{
			// 实际起始位置
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = partnerOrderInfoDao.getPartnerSaleCnt(parm);
			while(totalSize >0 && totalSize <= skipResults){//当记录总数 小于 起始位置数
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			// 分页检索
			parm.put("pageSize", pageSize);
			parm.put("skipResults", skipResults);
			List<PartnerSaleDto> list=new ArrayList<PartnerSaleDto>();
			list=partnerOrderInfoDao.getPartnerSaleInfo(parm);
			result = new JspPage(skipResults, totalSize, pageSize, list);
		}catch(Exception e){
			System.out.println(e.getMessage());
		}
		return result;
	}
	
	public Long calPartnerBonus(Map<String,Object> param) {
		return partnerOrderInfoDao.calPartnerBonus(param);
	}

	public PartnerOrderInfoDao getPartnerOrderInfoDao() {
		return partnerOrderInfoDao;
	}
	public void setPartnerOrderInfoDao(PartnerOrderInfoDao partnerOrderInfoDao) {
		this.partnerOrderInfoDao = partnerOrderInfoDao;
	}
}
